package com.xiang;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.xiang.thread.ThreadPoolUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CompletableFuture;

@Slf4j
public class ThreadPoolMain {
    public static TransmittableThreadLocal<String> context = new TransmittableThreadLocal<>();


    public static void main(String[] args) {
//        context.set("value-set-in-parent");

        for (int i = 0; i < 5; i++) {
//            CompletableFuture.runAsync(() -> {
//                        String value = context.get();
//                        log.info("内1 value: {}", value);
//                    }, ThreadPoolUtil.executorService).exceptionally(e->{
//                        log.error("ex1:",e);
//                        return null;
//                    })
//                    .thenRunAsync(() -> {
//                        String value = context.get();
//                        log.info("内2 value: {}", value);
//                    }, ThreadPoolUtil.executorService).exceptionally(e->{
//                        log.error("ex2:",e);
//                        return null;
//                    });


            ThreadPoolUtil.executorService.submit(()->{
                String value = context.get();
                log.info("内1 value: {}", value);
            });

        }

        ThreadPoolUtil.executorService.shutdown();

    }
}
